//
//  CJYCTableHeaderView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/6/13.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "CJYCTableHeaderView.h"

@implementation CJYCTableHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
    UILabel *contLab = [UILabel new];
    CGFloat W = 1.0/6;
    NSArray *array = @[@"学生",@"学号",@"考试次数",@"上升名次",@"操作"];
    for (int i = 0; i<5; i++) {
        if (i == 0) {
            UILabel *label = [[UILabel alloc]init];
            label.textAlignment = 1;
            label.textColor = TITLECOLOR;
            label.font = [UIFont systemFontOfSize:15];
            label.text = array[i];
            [self addSubview:label];
            label.tag = 20+i;
            contLab = label;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@0);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
        } else if(i==4){
            UILabel *label = [[UILabel alloc]init];
            label.textAlignment = 1;
            label.textColor = TITLECOLOR;
            label.text = array[i];
            label.font = [UIFont systemFontOfSize:15];
            [self addSubview:label];
            label.tag = 20+i;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W*2);
                make.height.mas_equalTo(40);
            }];
            contLab = label;
        }else{
            UILabel *label = [[UILabel alloc]init];
            label.textAlignment = 1;
            label.textColor = TITLECOLOR;
            label.font = [UIFont systemFontOfSize:15];
            label.text = array[i];
            [self addSubview:label];
            label.tag = 20+i;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
            contLab = label;
        }
    }
}
- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(0,50)];
    [path addLineToPoint:CGPointMake(self.frame.size.width, 50)];
    [LINCOLOR set];
    [path stroke];
    UIBezierPath *pathTop = [[UIBezierPath alloc]init];
    [pathTop moveToPoint:CGPointMake(0,0)];
    [pathTop addLineToPoint:CGPointMake(self.frame.size.width, 0)];
    [LINCOLOR set];
    [pathTop stroke];
    CGFloat W = self.frame.size.width/6.0;
    for (int i = 1; i<5; i++) {
        UIBezierPath *pathNext =[[UIBezierPath alloc]init];
        [pathNext moveToPoint:CGPointMake(W*i,0)];
        [pathNext addLineToPoint:CGPointMake(W*i, 50)];
        [LINCOLOR set];
        [pathNext stroke];
    }
}
@end
